﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using trunk.Models;
using trunk.ViewModels;

namespace trunk.Views
{
    /// <summary>
    /// MainPage.xaml 的交互逻辑
    /// </summary>
    public partial class MainPage : Page
    {
        public MainPage()
        {
            InitializeComponent();
            this.DataContext = new MainPageViewModel();

            CommandBindings.Add(new CommandBinding(WpfControlCommand, WpfControlExecuted, WpfControlCanExecute));
            CommandBindings.Add(new CommandBinding(SizePosTransCommand, SizePosTransExecuted, SizePosTransCanExecute));
            CommandBindings.Add(new CommandBinding(PanelLayoutCommand, PanelLayoutExecuted, PanelLayoutCanExecute));
            CommandBindings.Add(new CommandBinding(TcpPageCommand,TcpPageExecuted, TcpPageCanExecute));
        }

        #region wpf控件
        public static RoutedCommand WpfControlCommand = new RoutedCommand();

        public void WpfControlExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            ShowPage sp = new ShowPage();
            this.NavigationService.Navigate(sp);
            e.Handled = true;
        }

        public void WpfControlCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
            e.Handled = true;
        }
        #endregion

        #region 尺寸缩放、定位与变换
        public static RoutedCommand SizePosTransCommand = new RoutedCommand();

        public void SizePosTransExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            //MessageBox.Show("message box ...   ");
            SizePosTransPage sp = new SizePosTransPage();
            this.NavigationService.Navigate(sp);
            e.Handled = true;
        }

        public void SizePosTransCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
            e.Handled = true;
        }
        #endregion

        #region 使用面板做布局
        public static RoutedCommand PanelLayoutCommand = new RoutedCommand();

        public void PanelLayoutExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            PanelLayoutPage sp = new PanelLayoutPage();
            this.NavigationService.Navigate(sp);
            e.Handled = true;
        }

        public void PanelLayoutCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
            e.Handled = true;
        }
        #endregion

        #region Tcp连接
        public static RoutedCommand TcpPageCommand = new RoutedCommand();

        public void TcpPageExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            //TcpPage sp = new TcpPage();
            //this.NavigationService.Navigate(sp);


            TcpIpClientWindow tcpClientWindow = new ();
            tcpClientWindow.Show();

            TcpIpListenerWindow tcpListener = new();
            tcpListener.Show();

            e.Handled = true;
        }

        public void TcpPageCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
            e.Handled = true;
        }
        #endregion
    }
}
